/**
 * Created with JetBrains PhpStorm.
 * User: lunjiang
 * Date: 13-1-23
 * Time: 下午3:29
 * To change this template use File | Settings | File Templates.
 */
$(document).ready(function(){
    /**
     *
     * @type {Array}
     * key='2012-08' //X轴 时间
     * pnum 计划编制
     * anum 在职人数
     * p P线人数
     * m M线人数
     */

    /**
     *
     * @type {Array}
     * time:时间
     * dimissReate:离职率
     * total:离职总人数
     * vnum:主动离职人数
     * pnum:被动离职人数
     */
     var dataSource = [{time:'2011年-第1季度',dimissRate:0.10,total:100,vrate:0.08,vnum:10,prate:0.02,pnum:90},
     {time:'2011年-第2季度',dimissRate:0.20,total:100,vrate:0.08,vnum:10,prate:0.12,pnum:90},
     {time:'2011年-第3季度',dimissRate:0.11,total:100,vrate:0.03,vnum:10,prate:0.08,pnum:90},
     {time:'2011年-第4季度',dimissRate:0.21,total:100,vrate:0.08,vnum:10,prate:0.13,pnum:90}];//计划编制



    dataSource = eval('('+data_list+')');
    if(!dataSource.length){
        $("#container").html('<div style="color: red;font:20px;margin: 100px auto;text-align: center;">暂无数据!!!</div>')
        return;
    }
     var xAxis = [];
     var vDataSource = [];//主动离职
     var pDataSource = [];//被动离职
     var rateSource = [];
     for(var i = 0,len= dataSource.length;i<len;i++){
     xAxis.push(dataSource[i].time);
     vDataSource.push(parseFloat(dataSource[i].vrate));
     pDataSource.push(parseFloat(dataSource[i].prate));
     rateSource.push(parseFloat(dataSource[i].dimissRate));
     }
     var chart = new Highcharts.Chart({
     chart: {
     renderTo: 'container',
     zoomType:'xy'
     //type: 'lin'
     },
     title: {
     text: ''
     },

     xAxis: {
     categories: xAxis,
     lineWidth:1,
     tickmarkPlacement:'on'

     },

     yAxis: {
     title: {
     text: ''
     },
     labels:{
     formatter: function() {
     return (this.value)+'%';
     }
     }
     },
     tooltip: {
     enabled: true,
     formatter: function() {
     for(var i= 0,len=dataSource.length;i<len;i++){

     if(dataSource[i].time == this.x){
     var obj = dataSource[i];
     var html = this.x +'离职率为'+obj.dimissRate+'%<br/>';
     html = html + '<b>主动'+obj.vnum+'人，被动'+obj.pnum+'人</b>';
     return html;
     }

     }
     //var html =this.x在职人数为;
     //return this.x+'-'+this.y;
     }
     },

     legend:{
        itemWidth:100
     },
     series: [
     {
     name: '主动离职',
     color: '#adc1dc',
     type: 'column',
     stack:"3",
     data: vDataSource
     }, {
     name: '被动离职',
     color: '#4572A7',
     type: 'column',
     stack:"3",
     data: pDataSource

     },{
             name: '离职率',
             data: rateSource,//离职率
             stack:"1",
             color:"#ef7612"
         }

     ]
     });

});